package com.ruoyi.organization.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.annotation.CommunityScope;
import com.ruoyi.common.utils.BizUtils;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.organization.domain.BizPeople;
import com.ruoyi.organization.domain.vo.BizConsultVo;
import com.ruoyi.organization.mapper.BizPeopleMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.organization.mapper.BizConsultMapper;
import com.ruoyi.organization.domain.BizConsult;
import com.ruoyi.organization.service.IBizConsultService;

/**
 * 居民评议Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-05-25
 */
@Service
public class BizConsultServiceImpl implements IBizConsultService 
{
    @Autowired
    private BizConsultMapper bizConsultMapper;
    @Autowired
    private BizPeopleMapper bizPeopleMapper;

    /**
     * 查询居民评议
     * 
     * @param consultId 居民评议主键
     * @return 居民评议
     */
    @Override
    public BizConsult selectBizConsultByConsultId(String consultId)
    {
        return bizConsultMapper.selectBizConsultByConsultId(consultId);
    }

    /**
     * 查询居民评议列表
     * 
     * @param bizConsult 居民评议
     * @return 居民评议
     */
    @Override
    @CommunityScope
    public List<BizConsultVo> selectBizConsultList(BizConsult bizConsult)
    {
        //bizConsult.setType(99l);
        List<BizConsult> bizConsults = bizConsultMapper.selectBizConsultList(bizConsult);
        List<BizConsultVo> bizConsultVos = new ArrayList<>();
        for (BizConsult consult : bizConsults) {
            BizConsultVo t = new BizConsultVo();
            BeanUtils.copyProperties(consult,t);
            bizConsultVos.add(t);
        }
        for (BizConsultVo bizConsultVo : bizConsultVos) {
            BizPeople bizPeople = this.bizPeopleMapper.selectBizPeopleByPeopleId(bizConsultVo.getPeopleId());
            bizConsultVo.setMobile(bizPeople.getPeopleMobile());
        }
        return bizConsultVos;
    }

    /**
     * 新增居民评议
     * 
     * @param bizConsult 居民评议
     * @return 结果
     */
    @Override
    public int insertBizConsult(BizConsult bizConsult)
    {
        bizConsult.setCreateTime(DateUtils.getNowDate());
        return bizConsultMapper.insertBizConsult(bizConsult);
    }

    /**
     * 修改居民评议
     * 
     * @param bizConsult 居民评议
     * @return 结果
     */
    @Override
    public int updateBizConsult(BizConsult bizConsult)
    {
        bizConsult.setUpdateTime(DateUtils.getNowDate());
        return bizConsultMapper.updateBizConsult(bizConsult);
    }

    /**
     * 批量删除居民评议
     * 
     * @param consultIds 需要删除的居民评议主键
     * @return 结果
     */
    @Override
    public int deleteBizConsultByConsultIds(String[] consultIds)
    {
        return bizConsultMapper.deleteBizConsultByConsultIds(consultIds);
    }

    /**
     * 删除居民评议信息
     * 
     * @param consultId 居民评议主键
     * @return 结果
     */
    @Override
    public int deleteBizConsultByConsultId(String consultId)
    {
        return bizConsultMapper.deleteBizConsultByConsultId(consultId);
    }
}
